# -*- coding:utf-8 -*-
import pygame
import sys

from src.alien.object import Bullet


def check_events(setting,screen,ship,bullets):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            print("game close")
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right=True
            elif event.key == pygame.K_LEFT:
                ship.moving_left = True
            elif event.key == pygame.K_UP:
                ship.moving_up = True
            elif event.key == pygame.K_DOWN:
                ship.moving_down = True
            elif event.key==pygame.K_SPACE:
                pass
                new_bullets=Bullet(setting,screen,ship)
                bullets.add(new_bullets)
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right=False
            elif event.key == pygame.K_LEFT:
                ship.moving_left = False
            elif event.key == pygame.K_UP:
                ship.moving_up = False
            elif event.key == pygame.K_DOWN:
                ship.moving_down = False



def update_screen(setting,screen,ship,bullets):
    screen.fill(setting.bg_color)

    for bullet in  bullets.sprites():
        bullet.draw_bullet()
    ship.blitme()
    pygame.display.flip()

def update_bullets(bullets):
    bullets.update()
    for bullet in bullets.copy():
        if bullet.rect.bottom<=0:
            bullets.remove(bullet)
            print("bullet剩余..."+str(len(bullets)))






